package models.admin;

import java.util.Collections;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.hibernate.envers.Audited;

import play.db.jpa.Model;

/**
 * @author rjanixz
 *
 */
@Entity
@Audited
public class Page extends Model {

	@Column(unique=true, nullable=false)
	private String name;
	private String description;
	@ManyToOne
	@JoinColumn(name="parentId")
	private Page parent;
	@ManyToOne
	@JoinColumn(name="moduleId")
	private Module module;
	@OneToMany(mappedBy="page")
	private List<PagePermission> pagePermissions;

	public String getParentName() {
		String parentName = "";
		if (parent != null) {
			parentName = parent.name;
		}
		return parentName;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Page getParent() {
		return parent;
	}

	public void setParent(Page parent) {
		this.parent = parent;
	}

	public Module getModule() {
		return module;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	public List<PagePermission> getPagePermissions() {
		if (pagePermissions == null) {
			pagePermissions = Collections.emptyList();
		}
		return pagePermissions;
	}

	public void setPagePermissions(List<PagePermission> pagePermissions) {
		this.pagePermissions = pagePermissions;
	}
	
}
